<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <title>查看全部订单</title>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="description" content="Write an awesome description for your new site here. You can edit this line in _config.yml. It will appear in your document head meta (for Google search results) and in your feed.xml site description.
">
    <link rel="stylesheet" th:href="@{/wxui/lib/weui.min.css}"/>
    <link rel="stylesheet" th:href="@{/wxui/css/jquery-weui.css}"/>
    <link rel="stylesheet" th:href="@{/wxui/css/style.css}"/>
</head>
<body ontouchstart>
<header class="wy-header" style="position:fixed; top:0; left:0; right:0; z-index:200;">
    <div class="wy-header-icon-back"><span></span></div>
    <div class="wy-header-title">订单管理</div>
</header>
<div class='weui-content'>
    <div class="weui-tab">
        <div class="weui-navbar" style="position:fixed; top:44px; left:0; right:0; height:44px; background:#fff;">
            <a class="weui-navbar__item proinfo-tab-tit font-14" href="#tab1"
               onclick="listOrderInfoAndDetil(null)">全部</a>
            <a class="weui-navbar__item proinfo-tab-tit font-14" href="#tab2" onclick="listOrderInfoAndDetil(0)">待付款</a>
            <a class="weui-navbar__item proinfo-tab-tit font-14" href="#tab3" onclick="listOrderInfoAndDetil(1)">待发货</a>
            <a class="weui-navbar__item proinfo-tab-tit font-14" href="#tab4" onclick="listOrderInfoAndDetil(2)">待收货</a>
            <a class="weui-navbar__item proinfo-tab-tit font-14" href="#tab5" onclick="listOrderInfoAndDetil(3)">待评价</a>
        </div>
        <div class="weui-tab__bd proinfo-tab-con" style="padding-top:87px;">
            <div id="tab1" class="weui-tab__bd-item ">
            </div>
            <div id="tab2" class="weui-tab__bd-item">
            </div>
            <div id="tab3" class="weui-tab__bd-item">
            </div>
            <div id="tab4" class="weui-tab__bd-item">
            </div>
            <div id="tab5" class="weui-tab__bd-item">
            </div>
        </div>
    </div>
</div>

<script th:src="@{/wxui/lib/jquery-2.1.4.js}"></script>
<script th:src="@{/wxui/lib/fastclick.js}"></script>
<script th:src="@{/wxui/js/jquery-weui.js}"></script>
<script th:inline="javascript">
    $(function () {
        FastClick.attach(document.body);
        var state = [[${ state==null? null:state}]];
        listOrderInfoAndDetil(state);
        if (state == 0) {
            $("[href$='#tab2']").addClass("weui-bar__item--on");
            $("#tab2").addClass("weui-tab__bd-item--active")
        }
        if (state == 1) {
            $("[href$='#tab3']").addClass("weui-bar__item--on");
            $("#tab3").addClass("weui-tab__bd-item--active")
        }
        if (state == 2) {
            $("[href$='#tab4']").addClass("weui-bar__item--on");
            $("#tab4").addClass("weui-tab__bd-item--active")
        }
        if (state == 3) {
            $("[href$='#tab5']").addClass("weui-bar__item--on");
            $("#tab5").addClass("weui-tab__bd-item--active")
        }
        if (state == null) {
            $("[href$='#tab1']").addClass("weui-bar__item--on");
            $("#tab1").addClass("weui-tab__bd-item--active")
        }

        $(".wy-header-icon-back").click(function () {
            location.href='/user/frontstage/goUserCenterPage'
        });

    });
</script>

<script>


    /*
    *用户删除订单
    * */
    $(document).on("click", ".ords-btn-dele", function () {
        var id = $(this).attr("orderid");
        $.confirm("您确定要删除此订单吗?", "确认删除?", function () {
            $.ajax({
                type: "post",
                url: "/orderInfo/frontStage/deleteOrder",
                data: {
                    'id': id
                },
                dataType: 'json',
                success: function (data) {
                    if(data.code==200){
                        $.toast("订单已经删除!");
                        listOrderInfoAndDetil(null);
                    }else {
                        $.toast(data.msg,"text");
                    }
                }
            })
        }, function () {
            //取消操作
        });
    });


    /**
     * 用户确认收货
     */
    $(document).on("click", ".receipt", function () {
       var  oredeId = $(this).attr("orderId");
        $.confirm("确认您已签收", "确认收货?", function () {
            $.ajax({
                type: "post",
                url: "/orderInfo/frontStage/confirmReceipt",
                data: {
                    'id': oredeId
                },
                dataType: 'json',
                success: function (data) {
                    if(data.code==200){
                        $.alert("五星好评送蓝豆哦，赶快去评价吧！");
                        listOrderInfoAndDetil(3);
                        $("[href$='#tab4']").removeClass("weui-bar__item--on");
                        $("#tab4").removeClass("weui-tab__bd-item--active")
                        $("[href$='#tab5']").addClass("weui-bar__item--on");
                        $("#tab5").addClass("weui-tab__bd-item--active")
                    }
                }
            })
        }, function () {
            //取消操作
        });
    });


    function listOrderInfoAndDetil(state) {
        $.ajax({
            type: "post",
            url: "/orderInfo/frontStage/selectOrderInfoAndDetil",
            data: {
                'state': state
            },
            dataType: 'json',
            success: function (data) {
                var content = "";
                $.each(data.data, function (i, item) {
                    content += '<div class="weui-panel weui-panel_access">';
                    content += '<div class="weui-panel__hd"><span>单号：' + item.no + '</span><span class="ord-status-txt-ts fr">' + item.stateName + '</span></div>';
                    content += '<div class="weui-media-box__bd  pd-10">';
                    $.each(item.orderInfoDetails, function (i, items) {
                        content += '<div class="weui-media-box_appmsg ord-pro-list">';
                        content += '<div class="weui-media-box__hd"><a href="/goods/front/detail/'+items.goodsId+'"><img class="weui-media-box__thumb" src="' + items.goodsImg + '" alt=""></a></div>';
                        content += '<div class="weui-media-box__bd">';
                        content += '<h1 class="weui-media-box__desc"><a href="/goods/front/detail/'+items.goodsId+'" class="ord-pro-link">' + items.title + '</a></h1>';
                        content += '<p class="weui-media-box__desc">型号:' + items.specificationsInfo + '</p>';
                        content += '<div class="clear mg-t-10">';
                        content += '<div class="wy-pro-pri fl">¥<em class="num font-15">' + items.price + '</em></div>';
                        content += '<div class="pro-amount fr"><span class="font-13">数量×<em class="name">' + items.num + '</em></span></div>';
                        content += '</div></div></div>';
                        if (item.state == 3) {
                            content += '<div class="weui-panel__ft h-40">';
                            content += '<div class="weui-cell weui-cell_access weui-cell_link oder-opt-btnbox weui-cell-comment">';
                            content += '<a href="/orderInfo/frontStage/goCommPage?goodsId='+items.goodsId+'&orderId='+item.id+'" class="ords-btn-com">去评价</a>';
                            content += '</div></div>';
                        }
                    });
                    content += '</div>';
                    content += '<div class="ord-statistics">';
                    // content += '<span>共<em class="num"></em>种商品，</span>';
                    content += '<span class="wy-pro-pri">总金额：¥<em class="num font-15">' + item.money + '</em></span>';
                    content += '<span>(含运费<b>￥' + item.freight + '</b>)</span></div>';
                    if (item.state != 3 && item.state != 4) {
                        content += '<div class="weui-panel__ft">';
                        content += '<div class="weui-cell weui-cell_access weui-cell_link oder-opt-btnbox">';
                        if (item.state == 0) {
                            content += '<a href="javascript:;" class="ords-btn-dele" orderId="'+item.id+'">删除订单</a><a href="/orderInfo/frontStage/goOrderDetilPage?orderInfoId=' + item.id + '" class="ords-btn-com">去付款</a>';
                        }
                        if (item.state == 1) {
                            content += '商品正在打包中，请您耐心等待....';
                        }
                        if (item.state == 2) {
                            content += ' <a href="javascript:;" class="ords-btn-com receipt" orderId="'+item.id+'">确认收货</a>';
                        }
                        content += ' </div></div></div>'
                    }
                });
                if (state == null) {
                    $("#tab1").html(content);
                }
                if (state == 0) {
                    $("#tab2").html(content);
                }
                if (state == 1) {
                    $("#tab3").html(content);
                }
                if (state == 2) {
                    $("#tab4").html(content);
                }
                if (state == 3) {
                    $("#tab5").html(content);
                }
            }
        });

    }


</script>
</body>
</html>
